import axios from "axios";
import { getToken } from "@/utils/auth";
import { PxMessage } from "px-ui";

// 通用获取员工号+用户名方法
export function getEmployeeIdAndName() {
  const employeeIdAndName = [];
  return axios({
    method: "post",
    url: "/ifp/account/user/listPage",
    data: {
      page: 1,
      pageSize: 9999
    },
    headers: {
      "Content-Type": "application/json",
      Authorization: "Bearer " + getToken().accessToken || "",
      facCode: localStorage.getItem("facCode") || ""
    }
  })
    .then(result => {
      if (result.data.code === 200) {
        result?.data?.data.forEach(item => {
          employeeIdAndName.push({ value: item.username, label: item.username + "-" + item.realName, phone: item.phone, userId: item.userId });
        });
        return employeeIdAndName;
      } else {
        PxMessage.error(result.data.msg);
        return [];
      }
    })
    .catch(error => {
      PxMessage.error(`${error}`);
      return [];
    });
}
